home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / lcppb.zip / LCPP09.ZIP / POINTOUT.CPP < prev    next >
C/C++ Source or Header  |  1991-07-08  |  866b  |  44 lines

  1. // pointout.cpp -- Demonstrate overloading output streams
  2.  
  3. //#include <stream.hpp>
  4. #include <iostream.h>
  5.  
  6. class point {
  7.   private:
  8.     int x, y;
  9.   public:
  10.     point() { x = y = 0; }
  11.     point(int xx, int yy) { x = xx; y = yy; }
  12.     void putx(int xx) { x = xx; }
  13.     void puty(int yy) { y = yy; }
  14.     int getx(void) { return x; }
  15.     int gety(void) { return y; }
  16.     friend ostream& operator<<(ostream& os, point &p);
  17. };
  18.  
  19. main()
  20. {
  21.   point p;
  22.  
  23.   cout << p << '\n';
  24.  
  25.   p.putx(100);
  26.   p.puty(200);
  27.  
  28.   cout << p << '\n';
  29. }
  30.  
  31. ostream& operator<<(ostream& os, point &p)
  32. {
  33.   os << "x == " << p.x << ", y == " << p.y;
  34.   return os;
  35. }
  36.  
  37.  
  38. // Copyright (c) 1990 by Tom Swan. All rights reserved
  39. // Revision 1.00    Date: 11/24/1990   Time: 11:12 pm
  40.  
  41. // Revision 1.01    Date: 07/08/1991   Time: 05:41 pm
  42. // Converted for Borland C++ 2.0
  43.  
  44.